﻿package phpas3{
	public function array_merge (...args:Array):Array{
	    // Merges elements from passed arrays into one array
	    //
	    // version: 1109.2015
	    // discuss at: http://phpjs.org/functions/array_merge
	    // +   original by: Brett Zamir (http://brett-zamir.me)
	    // +   bugfixed by: Nate
	    // +   input by: josh
	    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	    // *     example 1: arr1 = {"color": "red", 0: 2, 1: 4}
	    // *     example 1: arr2 = {0: "a", 1: "b", "color": "green", "shape": "trapezoid", 2: 4}
	    // *     example 1: array_merge(arr1, arr2)
	    // *     returns 1: {"color": "green", 0: 2, 1: 4, 2: "a", 3: "b", "shape": "trapezoid", 4: 4}
	    // *     example 2: arr1 = []
	    // *     example 2: arr2 = {1: "data"}
	    // *     example 2: array_merge(arr1, arr2)
	    // *     returns 2: {0: "data"}
	    var argl:uint = args.length,
	        arg,
	        retObj:Array = new Array(),
	        k = '',
	        argil = 0,
	        j = 0,
	        i = 0,
	        ct = 0,
	        toStr = Object.prototype.toString,
	        retArr = true;

	    for (i = 0, ct = 0; i < argl; i++) {
	        arg = args[i];
            for (k in arg) {
                if (arg.hasOwnProperty(k)) {
                    if (parseInt(k, 10) + '' === k) {
                        retObj[ct++] = arg[k];
                    } else {
                        retObj[k] = arg[k];
                    }
                }
            }
	    }
	    return retObj;
	}
}